﻿jQuery.noConflict();

///replaces the OOB event handler for the onclick of the OK button in the AssetPicker
///the new event handler will return the value the LocationUrl textbox through the callback
function CustomizeOKButtonOfAssetPicker() {
    if (IsSobiensAssetPicker()) {
        var buttonOK = jQuery("input[value='OK']");
        buttonOK.removeAttr('onclick');
        buttonOK.click(function () {
            var textBoxLocationValue = jQuery("input[id$='LocationUrl']").val();
            SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, textBoxLocationValue);
        });
    }
}

function IsSobiensAssetPicker() {
    return (location.pathname.indexOf("AssetPortalBrowser.aspx") !== -1) && (parent.document.getElementById("dialogTitleSpan").innerText == "my title")
}

jQuery(document).ready(function () {
    CustomizeOKButtonOfAssetPicker();
});
